<label for="chanxian"><g:message code="moc.ta.select.chanxian.label" />:</label> 
<g:select name="line" id="chanxian" onchange="return lineChanged(this.value)"/>

<script>
	$(document).ready(function(){
		$.ajax({
			url: "${createLink(controller:'ajax', action: 'workshop')}",
			success: function(data){
				$("#chanxian").append("<option value='-'>-</option>");
				for(var i=0; i<data.length; i++){
					$("#chanxian").append("<option value='"+$.trim(data[i])+"'>"+$.trim(data[i])+"</option>");
				}
				$("#chanxian").val("${params.line}");
			}
		});
	});
	
	function setUrlParam(url, param, v){
		var re = new RegExp("(\\\?|&)" + param + "=([^&]+)(&|$)", "i");
		var m = url.match(re);
		if (m){
			return (url.replace(re, function($0, $1, $2) { return ($0.replace($2, v)); } ));
		}else{
			if (url.indexOf('?') == -1)
				return (url + '?' + param + '=' + v);
			else
				return (url + '&' + param + '=' + v);
		}
	}
	function getUrlParam(url, param){
		var re = new RegExp("(\\\?|&)" + param + "=([^&]+)(&|$)", "i");
		var m = url.match(re);
		if (m)
			return m[2];
		else
			return '';
	}
	function lineChanged(value){
		setUrlParam(window.location.href, "offset", 0);
		setUrlParam(window.location.href, "max", 100);
		window.location.href = setUrlParam(window.location.href, "line", encodeURI(value));
	}
</script>
Total=${tbInstanceTotal}
<br/>


<table>
    <thead>
        <tr>
            <g:sortableColumn property="tb001" title="${message(code: 'moc.tb.tb001.label', default: 'Tb001')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb002" title="${message(code: 'moc.tb.tb002.label', default: 'Tb002')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb008" title="${message(code: 'moc.tb.tb008.label', default: 'Tb008')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb003" title="${message(code: 'moc.tb.tb003.label', default: 'Tb003')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb011" title="${message(code: 'moc.tb.tb011.label', default: 'Tb011')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb012" title="${message(code: 'moc.tb.tb012.label', default: 'Tb012')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb004" title="${message(code: 'moc.tb.tb004.label', default: 'Tb004')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb005" title="${message(code: 'moc.tb.tb005.label', default: 'Tb005')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb006" title="${message(code: 'moc.tb.tb006.label', default: 'Tb006')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb006" title="${message(code: 'moc.tb.tb007.label', default: 'Tb007')}"  params="[line : params.line]"/>
            <g:sortableColumn property="beginDate" title="${message(code: 'moc.tb.beginDate.label', default: 'Begin Date')}"  params="[line : params.line]"/>
            <g:sortableColumn property="endDate" title="${message(code: 'moc.tb.endDate.label', default: 'End Date')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb009" title="${message(code: 'moc.tb.tb009.label', default: 'Tb009')}"  params="[line : params.line]"/>
            <g:sortableColumn property="tb010" title="${message(code: 'moc.tb.tb010.label', default: 'Tb010')}"  params="[line : params.line]"/>
            <g:sortableColumn property="status" title="${message(code: 'moc.tb.status.label', default: 'Status')}"  params="[line : params.line]"/>
        </tr>
    </thead>
    <tbody>
    <g:each in="${tbInstanceList}" status="i" var="tbInstance">
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
        	<td><g:link controller="tb" action="show" id="${tbInstance.id}">${fieldValue(bean: tbInstance, field: "tb001")}</g:link></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb002")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb008")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb003")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb011")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb012")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb004")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb005")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb006")}</a></td>
        	<td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${tbInstance?.tcs*.tc002.sum()} </a></td>
            <td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank"><g:formatDate format="yyyy-MM-dd" date="${tbInstance.beginDate}" /></a></td>
            <td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank"><g:formatDate format="yyyy-MM-dd" date="${tbInstance.endDate}" /></a></td>
            <td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb009")}</a></td>
            <td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "tb010")}</a></td>                        
            <td><a href="${createLink(controller:'tc', action:'create', params : [tb_id : tbInstance.id])}" target="_blank">${fieldValue(bean: tbInstance, field: "status")}</a></td>                    
        </tr>
    </g:each>
    </tbody>
</table>
